package com.itmuch.common.feignset.hystix;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.ArrayList;
import java.util.List;

//把@ComponentScan 的功能加入到spring.factorys，让子类来自己控制需要加载那些类，顶层的框架不管启动
/**
 * 如果项目里面，要发起一个feignclient的逻辑，需要把这个启动打开，扫描到，不然就执行不了拦截功能
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author xiaocaiwen
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Configuration
@ConditionalOnClass({QfHystrixRequestContextEnablerFilter.class })
//级联去引用其他的bean先扫描
@Import(value={QfHystrixRequestContextEnablerFilter.class,QfHystrixConcurrencyStrategy.class})
public class FeignRequestFilterAutoConfiguration {
	
	@Autowired
	private QfHystrixRequestContextEnablerFilter fitler;
	 
	@Bean
	public FilterRegistrationBean filterRegistrationBean() {
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		List<String> urlPatterns = new ArrayList<String>();
		urlPatterns.add("/*");
		registrationBean.setOrder(1);
		registrationBean.setFilter(fitler);
		registrationBean.setUrlPatterns(urlPatterns);
		QfHystrixRequestContextEnablerFilter.ENABLED_HYSTRIX_FILTER = true;
		return registrationBean;
	}


}
